<template>
	<view class="content">
		<top-card></top-card>
		<basc-info></basc-info>
		<edu-info></edu-info>
		<work-info></work-info>
		<get-about></get-about>
		<view class="creat">
			<u-icon name="plus-circle-fill" color="#2979ff" size="120" @click="creat_fun"></u-icon>
		</view>
		<!-- 底部导航 -->
		<get-tab :is_tabbar="is_tabbar"></get-tab>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import getTab from '@/components/common/tabbar.vue'
	import topCard from '@/components/index/top_card.vue'
	import bascInfo from '@/components/index/bascinfo.vue'
	import eduInfo from '@/components/index/eduinfo.vue'
	import workInfo from '@/components/index/workinfo.vue'
	import getAbout from '@/components/index/about.vue'
	export default {
		components:{
			getTab,
			topCard,
			bascInfo,
			eduInfo,
			workInfo,
			getAbout
		},
		data() {
			return {
				is_tabbar:1
			}
		},
		onLoad() {
			var user_data = uni.getStorageSync('user_data')
			if(user_data){
				this.is_tabbar=2
			}
		},
		methods: {
		  creat_fun(){
			  /* uni.navigateTo({
			  	url:'/pages/center/creat'
			  }) */
			  if(this.is_tabbar==1){
				 this.getuser() 
			  }else{
				  uni.navigateTo({
				  	url:'/pages/center/creat'
				  })
			  }

		  },
		  getuser(){
			  var self = this
			  uni.showModal({
			  	title: '登录',
			  	content: '请您先登录系统',
			  	success: function (res) {
			  		if (res.confirm) {
			  			uni.login({
			  				success: (res_login) => {
			  					//console.log(res_login)
			  								if(res_login.code){
			  									/* self.$refs.uToast.show({
			  										title: '登录成功',
			  										type: 'success',
			  										url: '/'
			  									}) */
			  									uni.getUserInfo({
			  										success: (res_data) => {
			  											//console.log(res_data.userInfo)
			  											var user = {
			  												nickname:res_data.userInfo['nickName'],
			  												avarar:res_data.userInfo['avatarUrl'],
			  											}
			  											uni.setStorage({
			  												key:'user_data',
			  												data:user,
			  												success:function(){
			  													self.$refs.uToast.show({
			  														title: '登录成功',
			  														type: 'success',
			  														url: '/pages/center/creat'
			  													})
			  												}
			  											})
			  										}
			  									})
			  								}else{
			  									self.$refs.uToast.show({
			  										title: '登录失败',
			  										type: 'error'
			  									})
			  								}
			  				}
			  			})
			  		} else if (res.cancel) {
			  			console.log('用户点击取消');
			  		}
			  	}
			  })
		  }
		}
	}
</script>

<style lang="scss">
	.content {
		.creat{
			width: 120rpx;
			height: 120rpx;
			background: #eeeeee;
			border-radius: 50%;
			position: fixed;
			bottom: 200rpx;
			right: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

</style>
